package ace.module.upms.core.impl.manager.impl;

import ace.cmp.core.constants.CoreConstant;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.module.upms.api.model.dto.UpmsOrganizationDto;
import ace.module.upms.core.impl.dao.entity.UpmsOrganization;
import ace.module.upms.core.impl.dao.repository.UpmsOrganizationRepository;
import ace.module.upms.core.impl.manager.UpmsOrganizationManager;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 组织 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class UpmsOrganizationManagerImpl
    extends AbstractSpringDtoManager<UpmsOrganization, Long, UpmsOrganizationDto>
    implements UpmsOrganizationManager {

  private final UpmsOrganizationRepository upmsOrganizationRepository;

  @Override
  public List<UpmsOrganization> getByUpmsAppIdAndIdInAndDeleteFlagIsFalse(Long upmsAppId, List<Long> orgIds) {
    return this.upmsOrganizationRepository.getByUpmsAppIdAndIdInAndDeleteFlagIsFalse(upmsAppId, orgIds, CoreConstant.DELETE_FLAG_NOT);
  }

  @Override
  public boolean anyMatch(List<UpmsOrganization> upmsOrganizations, Long upmsOrgId) {
    return upmsOrganizations.stream().anyMatch(p -> p.getId().equals(upmsOrgId));
  }
}
